package com.ifacebox.client.tools;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @author znn
 */
public class FacePersonInfo {
    private String idNumber;
    private String idName;
    private String phoneNumber;
    private String companyName;
    private String businessName;

    public FacePersonInfo() {
        this.setIdNumber("");
        this.setIdName("");
        this.setPhoneNumber("");
        this.setCompanyName("");
        this.setBusinessName("");
    }

    public String getIdNumber() {
        return idNumber;
    }

    public void setIdNumber(String idNumber) {
        this.idNumber = idNumber;
    }

    public String getIdName() {
        return idName;
    }

    public void setIdName(String idName) {
        this.idName = idName;
    }

    public String getPhoneNumber() {
        return phoneNumber;
    }

    public void setPhoneNumber(String phoneNumber) {
        this.phoneNumber = phoneNumber;
    }

    public String getCompanyName() {
        return companyName;
    }

    public void setCompanyName(String companyName) {
        this.companyName = companyName;
    }

    public String getBusinessName() {
        return businessName;
    }

    public void setBusinessName(String businessName) {
        this.businessName = businessName;
    }

    public String toTips(String tips) {
        if (tips != null && tips.length() > 0) {
            tips = tips.replaceAll("\\{idNumber}", this.parseIdNumber(this.getIdNumber()));
            tips = tips.replaceAll("\\{idName}", this.parseIdName(this.getIdName()));
            tips = tips.replaceAll("\\{phoneNumber}", this.parsePhoneNumber(this.getPhoneNumber()));
            tips = tips.replaceAll("\\{companyName}", this.getCompanyName());
            tips = tips.replaceAll("\\{businessName}", this.getBusinessName());
        }
        return tips;
    }

    public String parseIdNumber(String idNumber) {
        if (idNumber != null) {
            return idNumber.replaceAll("(?<=.{4}).(?=.{4})", "*");
        }
        return null;
    }

    public String parseIdName(String idName) {
        if (idName != null && idName.length() >= 1) {
            return idName.replaceAll("(?<=.)." + (idName.length() > 2 ? "(?=.)" : ""), "*");
        }
        return idName;
    }

    public String parsePhoneNumber(String phoneNumber) {
        if (phoneNumber != null) {
            return phoneNumber.replaceAll("(?<=.{3}).(?=.{4})", "*");
        }
        return null;
    }

    @Override
    public String toString() {
        return "|" +
                "身份证号码:" + this.getIdNumber() + "|" +
                "姓名:" + this.getIdName() + "\t|" +
                "手机号码:" + this.getPhoneNumber() + "|" +
                "公司:" + this.getCompanyName() + "\t|" +
                "职务:" + this.getBusinessName() + "\t|" +
                "时间:" + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()) + "|";
    }

}
